package com.dog.basics.admin.controller.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.admin.common.ArticleAddDto;
import com.dog.basics.bean.dto.admin.common.ArticleEditDto;
import com.dog.basics.bean.dto.admin.common.ArticleFormDto;
import com.dog.basics.bean.vo.admin.common.PcArticleVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.common.IDogComArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

/**
 * <p>
 * CMS文章表 前端控制器
 * </p>
 *
 * @author guonh
 * @since 2020-05-20
 */
@RestController
@RequestMapping("/admin/article")
@Api(value = SwaggerConstants.COMMON+"CMS文章模块", tags = SwaggerConstants.COMMON+"CMS文章模块")
@AllArgsConstructor
@ApiIgnore
public class DogComArticleController {
    private final IDogComArticleService iDogComArticleService;


    /**
     * @Description: 增加CMS文章
     * @Param:
     * @return: Boolean
     * @Author: zhangrm
     * @Date: 2020/05/22  0027
     */
    @SysLog("增加CMS文章")
    @ApiOperation(value = "增加CMS文章", notes = "admin:article:save")
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('admin:article:save')")
    public R<Boolean> save(@Valid @RequestBody ArticleAddDto obj) {
        return R.ok(iDogComArticleService.saveObj(obj));
    }

    /**
     * @Description: 删除CMS文章
     * @Param: ids
     * @return: Boolean
     * @Author: zhangrm
     * @Date: 2020/05/22  0027
     */
    @SysLog("删除CMS文章")
    @ApiOperation(value = "删除CMS文章", notes = "admin:article:delete")
    @ApiImplicitParam(value = "CMS文章Id", name = "id", dataType = "Long", required = true)
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("@pms.hasPermission('admin:article:delete')")
    public R<Boolean> delete(@PathVariable("id") Long id) {
        return R.ok(iDogComArticleService.deleteObj(id));
    }


    /**
     * @Description: 修改CMS文章
     * @Param:
     * @return: Boolean
     * @Author: zhangrm
     * @Date: 2020/05/22  0027
     */
    @SysLog("修改CMS文章")
    @ApiOperation(value = "修改CMS文章", notes = "admin:article:edit")
    @PutMapping("/edit")
    @PreAuthorize("@pms.hasPermission('admin:article:edit')")
    public R<Boolean> edit(@Valid @RequestBody ArticleEditDto obj) {
        return R.ok(iDogComArticleService.editObj(obj));
    }

    /**
     * @Description: CMS文章回收
     * @Param:
     * @return: Boolean
     * @Author: zhangrm
     * @Date: 2020/05/22  0027
     */
    @SysLog("CMS文章回收")
    @ApiOperation(value = "CMS文章回收", notes = "admin:article:back")
    @PutMapping("/back")
    @ApiImplicitParam(name = "id" ,value = "文章ID" ,required = true,dataType = "Long")
    @PreAuthorize("@pms.hasPermission('admin:article:back')")
    public R<Boolean> back(Long id) {
        return R.ok(iDogComArticleService.back(id));
    }

    /**
     * @Description: CMS文章审核
     * @Param:
     * @return: Boolean
     * @Author: zhangrm
     * @Date: 2020/05/22  0027
     */
    @SysLog("CMS文章审核")
    @ApiOperation(value = "CMS文章审核", notes = "admin:article:examine")
    @PutMapping("/examine")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id" ,value = "文章ID" ,required = true,dataType = "Long"),
            @ApiImplicitParam(name = "status" ,value = "2-已发布 4 审核打回" ,required = true,dataType = "Integer" )
    })
    @PreAuthorize("@pms.hasPermission('admin:article:examine')")
    public R<Boolean> examine(Long id , Integer status ) {
        return R.ok(iDogComArticleService.examine(id ,status));
    }



    /**
     * @Description: 分页CMS文章列表
     * @Param:
     * @return:
     * @Author: zhangmr
     * @Date:
     */
    @ApiOperation(value = "分页CMS文章列表", notes = "admin:article:page")
    @GetMapping("/page")
    @PreAuthorize("@pms.hasPermission('admin:article:page')")
    public R<IPage<PcArticleVo>> page(PageParam page, ArticleFormDto obj) {
        IPage<PcArticleVo> list = iDogComArticleService.getPageList(page, obj);
        return R.ok(list);
    }

}
